/**
 * 
 */
package br.com.lazyprogrammer.worldsoccermanager.preferences;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import br.com.lazyprogrammer.worldsoccermanager.preferences.interfaces.ActionPreferences;
import br.com.lazyprogrammer.worldsoccermanager.preferences.interfaces.OnPreferencesChangedListener;

/**
 * 
 * @author Limao Games <br />
 * <b>Email:</b> andreikeda@limaogames.com.br <br />
 * created on: 13/01/2014
 * @version 1.0
 * @see 
 */
public class Preferences implements ActionPreferences, OnPreferencesChangedListener {
	
	private static final String PREF_FB_ID		= "fb_id";
	private static final String PREF_PASSWORD	= "password";
	private static final String PREF_USER_ID	= "user_id";
	private static final String PREF_USERNAME	= "username";
	
	private SharedPreferences mPref;
	private Editor edit;
	
	public Preferences(Context context, String prefName) {
		mPref	= context.getSharedPreferences(prefName, Context.MODE_PRIVATE);
	}
	
	@Override
	public String getFacebookId() {
		return mPref.getString(PREF_FB_ID, "0");
	}
	
	@Override
	public String getPassword() {
		return mPref.getString(PREF_PASSWORD, "");
	}
	
	@Override
	public String getUserId() {
		return mPref.getString(PREF_USER_ID, "");
	}

	/* (non-Javadoc)
	 * @see br.com.limaogames.app.communication.eai.interfaces.ActionPreferences#getUsername()
	 */
	@Override
	public String getUsername() {
		return mPref.getString(PREF_USERNAME, "");
	}
	
	@Override
	public boolean isUserLogged() {
		return !mPref.getString(PREF_USERNAME, "").equals("");
	}
	
	@Override
	public void onFacebookIdChanged(String fbId) {
		edit	= mPref.edit();
		edit.putString(PREF_FB_ID, fbId);
		edit.commit();
	}

	/* (non-Javadoc)
	 * @see br.com.limaogames.app.communication.eai.interfaces.OnPreferencesChangedListener#onPasswordChanged()
	 */
	@Override
	public void onPasswordChanged(String password) {
		edit	= mPref.edit();
		edit.putString(PREF_PASSWORD, password);
		edit.commit();
	}

	/* (non-Javadoc)
	 * @see br.com.limaogames.app.communication.eai.interfaces.OnPreferencesChangedListener#onUsernameChanged()
	 */
	@Override
	public void onUsernameChanged(String username) {
		edit	= mPref.edit();
		edit.putString(PREF_USERNAME, username);
		edit.commit();
	}
	
	@Override
	public void onUserIdChanged(String userId) {
		edit	= mPref.edit();
		edit.putString(PREF_USER_ID, userId);
		edit.commit();
	}

}
